﻿#if DEBUG

using System;
using MLSharp;
using MLSharp.Classification;

namespace MLSharp.ConsoleRunner.Tests
{
	/// <summary>
	/// A classifier factory that can be used for testing.
	/// </summary>
	/// <typeparam name="T"></typeparam>
	internal class GenericClassifierFactory<T> : IClassifierFactory where T : IClassifier, new()
	{
		/// <summary>
		/// Returns the classifier.
		/// </summary>
		/// <param name="trainingData"></param>
		/// <returns></returns>
		public IClassifier BuildClassifier(IDataSet trainingData)
		{
			return new T();
		}

		/// <summary>
		/// Doesn't do anything.
		/// </summary>
		public object Options
		{
			get { throw new NotImplementedException(); }
		}
	}

	/// <summary>
	/// A classifier that always makes bad predictions.
	/// </summary>
	internal class BadClassifier : IClassifier
	{
		/// <summary>
		/// Classifies the data set.
		/// </summary>
		/// <param name="dataSet"></param>
		/// <returns></returns>
		public ClassificationResult[] Classify(IDataSet dataSet)
		{
			ClassificationResult[] results = new ClassificationResult[dataSet.Instances.Count];

			for (int i = 0; i < dataSet.Instances.Count; i++)
			{
				Instance instance = dataSet.Instances[i];

				string prediction = dataSet.Attributes[dataSet.TargetAttributeIndex].PossibleValues[
					instance.Values[dataSet.TargetAttributeIndex] == 0 ? 1 : 0];

				results[i] = new ClassificationResult(prediction, instance.ClassValue)
				             	{
				             		ID = instance.Label,
				             		Confidence = 1.0
				             	};
			}

			return results;
		}
	}

	/// <summary>
	/// Always makes the correct classification.
	/// </summary>
	internal class GoodClassifier : IClassifier
	{
		/// <summary>
		/// Classifies the data.
		/// </summary>
		/// <param name="dataSet"></param>
		/// <returns></returns>
		public ClassificationResult[] Classify(IDataSet dataSet)
		{
			ClassificationResult[] results = new ClassificationResult[dataSet.Instances.Count];

			for (int i = 0; i < dataSet.Instances.Count; i++)
			{
				Instance instance = dataSet.Instances[i];

				results[i] = new ClassificationResult(instance.ClassValue, instance.ClassValue)
				{
					ID = instance.Label,
					Confidence = 1.0
				};
			}

			return results;
		}
	}
}

#endif
